//
//  TimelineModel.m
//  MVC|MVP|MVVM
//
//  Created by Guo Rui on 2017/11/13.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "TimelineModel.h"
#import <YYModel.h>
#import "NSObject+Orientation.h"

@implementation TimelineModel

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass
{
    return @{ @"mediaList" : MediaModel.class };
}


#pragma mark - MVCTableViewCellProtocol

- (MediaModel *)mediaModel
{
    MediaModel *mediaModel = [self.mediaList firstObject];
    if (!mediaModel) {
        return nil;
    }
    
    UIImageOrientation orientation = [self exifOrientationToIOSOrientation:mediaModel.imageOrientation];
    if (orientation == UIImageOrientationLeft || orientation == UIImageOrientationRight) {
        NSNumber *temp = mediaModel.w;
        mediaModel.w = mediaModel.h;
        mediaModel.h = temp;
    }
    
    return mediaModel;
}

- (NSString *)timelineContent
{
    if (self.content == nil || self.content.length == 0) {
        return nil;
    }
    return self.content;
}

- (NSString *)publishInfo
{
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString *dotime = [fmt stringFromDate:[NSDate dateWithTimeIntervalSince1970:self.date.floatValue / 1000]];
    return [NSString stringWithFormat:@"%@发布于%@", self.author.relationName, dotime];
}

- (BOOL)isLike
{
    return self.like;
}

@end
